package com.leyou.item.mapper;

import com.leyou.item.entity.Brand;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.additional.idlist.SelectByIdListMapper;
import tk.mybatis.mapper.common.BaseMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @version V1.0
 * @author: Ljxpa
 * @date: 2020/03/04 16:58
 * @description:
 */
public interface BrandMapper extends  Mapper<Brand>,SelectByIdListMapper<Brand,Long> {
	// int addBrand(Long id, List<Integer> cids);
	int addBrand(@Param("brandId") Long brandId, @Param("cids") List<Integer> cids);

	@Update("update tb_brand set name = #{name},letter = #{letter},update_time = #{updateTime},image=#{image} where id = #{id}")
	int updateBrandById(Brand brand);

	@Delete("delete from tb_category_brand where brand_id = #{brandId}")
	int delRelationByBrandId(@Param("brandId") Long id);

	@Delete("delete from tb_brand where id = #{bid}")
	int delBrand(@Param("bid") Long bid);

	@Select("SELECT tb.id,tb.name,tb.image,tb.letter,tb.create_time,tb.update_time FROM tb_brand tb INNER JOIN  tb_category_brand tcb ON tb.id = tcb.brand_id WHERE tcb.category_id = #{cid} ")
	List<Brand> queryBrandByCid(@Param(("cid")) Long cid);
}
